package com.jiruan.invoicemanagementsystem.service.imp;

import com.jiruan.invoicemanagementsystem.dao.IInvoicingRecordDao;
import com.jiruan.invoicemanagementsystem.dao.Imp.IInvoicingRecordDaoImp;
import com.jiruan.invoicemanagementsystem.pojo.InvoicingRecord;
import com.jiruan.invoicemanagementsystem.service.IInvoicingRecord;
import com.jiruan.invoicemanagementsystem.util.PageHelper;
import com.jiruan.invoicemanagementsystem.vo.InvoicingRecordDetail;
import com.jiruan.invoicemanagementsystem.vo.InvoicingRecordShow;
import com.jiruan.invoicemanagementsystem.vo.StatisticalInfoShow;

import java.util.ArrayList;

public class IInvoicingRecordImp implements IInvoicingRecord {

    IInvoicingRecordDao iird=new IInvoicingRecordDaoImp();



    //获取开票记录表中所有开票记录的    已用发票金额总和，  数据里发票金额总和  合起来得出 历史已开票
    @Override
    public Double getTAofHistoricalInvoice() {
        Double History=0.0;
        StatisticalInfoShow sis=new StatisticalInfoShow();
        ArrayList<InvoicingRecord> invoicingRecords=iird.getTotalInvoicingRecord();

        for (InvoicingRecord i:invoicingRecords){  //遍历数据库中每条历史已用金额
            History+=i.getAmount();
        }
//        sis.setTaoHistoricalInvoice(String.valueOf(History)); //存入所有数据总金额，并在sis对象设得可开票金额


//        return Double.parseDouble(sis.getCanInvoiceAmount());
        return History;
    }


    /**
     * @功能: 分页查询
     * @步骤: 1.根据条件得到本次分页查询的数据总条数
     *       2.根据使用数据总条数得到总页数并包装着当前页码的DBHelper与条件查询本次分页的数据集合
     * @param
     *  invoicingRecord: 封装着条件:包括"发票申请日期"、"处理状态"，"发票种类"
//     *                 "发票抬头"  不要了
     *  min: 发票金额条件的最小值
     *  max: 发票金额条件的最大值
     * */


    @Override
    public int getCountOfInvoicingRecord(InvoicingRecordShow invoicingRecord, Double min, Double max) {
        return iird.getCountOfInvoicingRecord(invoicingRecord,min,max);
    }

    @Override
    public ArrayList< InvoicingRecordShow> getMessageOfInvoicingRecord(PageHelper pageHelper,  InvoicingRecordShow invoicingRecord, Double min, Double max) {

        return iird.selectInvoicingRecordPage(invoicingRecord,pageHelper,min,max);
    }



//退票操作
    /*
     * 根据"上链地址"找到对应数据
     * 更新对应的开票记录状态(status)为'B' -> 已退票
     * */

//A。已开票
    @Override
    public boolean  refundTickById(String upLinkAddress) {
        return iird.refundTickById(upLinkAddress)>0;
    }



    //根据invoicingrecord的uplinkAddress 上链地址 category 发票种类 type获得发票类型    basedata的 enterpriseId 抬头
    // taxNo税号  email的emailDetail邮箱

    public InvoicingRecordDetail getInvoicingAccordingTo(String uplinkAddress){
        return iird.queryInvoicingAccordingTo(uplinkAddress);
    }










}
